#ifndef BREAKPOINTS_HPP
#define BREAKPOINTS_HPP

#include <QDockWidget>
#include <QMap>
#include <QTableWidgetItem>
#include <QMapIterator>

#include "programmanagement.hpp"
#include "command.hpp"

namespace Ui {
    class Breakpoints;
}

/**
* @brief QDockWidget Breakpoints
* @details This DockWidget shows all available Breakpoints in the current program. \n
* It is possible to jump directly to a selected Breakpoint with a double-click. \n
* The following information will be stored for a Breakpoint: line, ASM-Code at this line
*
* @class Breakpoints breakpoints.hpp "breakpoints.hpp"
*/
class Breakpoints : public QDockWidget {
    Q_OBJECT
public:
    /**
    * @brief Breakpoints default Constructor
    *
    * @fn Breakpoints(QWidget *parent = 0)
    * @param parent
    */
    Breakpoints(QWidget *parent = 0);

    /**
    * @brief Breakpoints Destructor
    *
    * @fn ~Breakpoints
    */
    ~Breakpoints();

    /**
    * @brief Reset the Breakpoints
    * @details This will reset the class to the standard \n
    * All Breakpoints will be deleted
    *
    * @fn reset
    */
    void reset();

protected:
    /**
    * @brief Action on ChangeEvent
    *
    * @fn void changeEvent(QEvent *e)
    * @param e
    */
    void changeEvent(QEvent *e);

private:
    /**
    * @brief struct Breakpoint (Aggregation of all needed informations for a single Breakpoint)
    * @details This struct contains all needed informations for a Breakpoint. \n
    * anchor : QString - The programAdress as String, needed to jump to this line in CodeView
    * line : QTableWidgetItem - The current line for this Breakpoint
    * code : QTableWidgetItem - The ASM-Code at the line of this Breakpoint
    *
    * @class Breakpoint breakpoints.hpp "breakpoints.hpp"
    */
    struct Breakpoint {
	QString anchor;
	QTableWidgetItem *line;
	QTableWidgetItem *code;
    };

    Ui::Breakpoints *ui;
    QMap<int, Breakpoint> breakpointMap;

public slots:
    /**
    * @brief A Breakpoint has been toggled
    * @details Slot will be called everytime a Breakpoint has been toggled in GUI \n
    * A new Breakpoint will be added to the internal memory
    *
    * @fn void onBreakpointToggled(int line, bool add, QString asmCode, QString anchor)
    * @param line
    * @param add
    * @param asmCode
    * @param anchor
    */
    void onBreakpointToggled(int line, bool add, QString asmCode, QString anchor);

private slots:
    /**
    * @brief Double Click on BreakpointView
    * @details Slot will be called when the user clicks on an entry in Breakpoint list \n
    * This will emit the signal \see{jumpToBreakpoint(QString anchor)} which causes the GUI to scroll to this Breakpoint
    *
    * @fn void on_tbl_breakpoints_cellDoubleClicked(int row, int column)
    * @param row
    * @param column
    */
    void on_tbl_breakpoints_cellDoubleClicked(int row, int column);

signals:
    /**
    * @brief Jump To a Breakpoint
    * @details Signal emitted to signal the GUI to scroll to a specified anchor \n
    * \see{on_tbl_breakpoints_cellDoubleClicked(int row, int column)}
    *
    * @fn void jumpToBreakpoint(QString anchor)
    * @param anchor
    */
    void jumpToBreakpoint(QString anchor);
};

#endif // BREAKPOINTS_HPP
